// Copyright@ChenChao


#include "Pawns/Bird.h"

#include "Camera/CameraComponent.h"
#include "Components/CapsuleComponent.h"
#include "Components/SkeletalMeshComponent.h"
#include "GameFramework/FloatingPawnMovement.h"
#include "GameFramework/SpringArmComponent.h"

ABird::ABird()
{
	PrimaryActorTick.bCanEverTick = true;
	
	/*胶囊体组件*/
	Capsule = CreateDefaultSubobject<UCapsuleComponent>(TEXT("CapsuleComponent"));
	Capsule->SetCapsuleHalfHeight(12.f);	//胶囊体半高
	Capsule->SetCapsuleRadius(15.f);		//胶囊体半径
	//Capsule->SetCapsuleSize(15.f, 12.f, true);		//胶囊体半径 半高
	SetRootComponent(Capsule);

	/*骨骼网格体组件*/
	BirdMesh = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("BirdMeshComponent"));
	BirdMesh->SetupAttachment(GetRootComponent());
	
	/*运动组件*/
	BirdMovement = CreateDefaultSubobject<UFloatingPawnMovement>(TEXT("BirdMovementComponent"));
	
	
	/*弹簧臂*/
	SpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("SpringArmComponent"));
	SpringArm->SetupAttachment(GetRootComponent()); 

	/*摄像机*/
	Camera = CreateDefaultSubobject<UCameraComponent>(TEXT("CameraComponent"));
	Camera->SetupAttachment(SpringArm); 

	/*使用控制器旋转和偏航*/
	bUseControllerRotationYaw = true;
	bUseControllerRotationPitch = true;
	/*自动控制器*/
	AutoPossessPlayer = EAutoReceiveInput::Player0;
}

void ABird::BeginPlay()
{
	Super::BeginPlay();
	
}


void ABird::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

}

/*调用以将功能绑定到输入*/
void ABird::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
	Super::SetupPlayerInputComponent(PlayerInputComponent);

	PlayerInputComponent->BindAxis(FName("MoveForward"), this, &ABird::F_MoveForward);
	PlayerInputComponent->BindAxis(FName("MoveRight"), this, &ABird::F_MoveRight);
	PlayerInputComponent->BindAxis(FName("Turn"), this, &ABird::F_Turn);
	PlayerInputComponent->BindAxis(FName("LookUp"), this, &ABird::F_LookUp);
}

/*函数:前后移动*/
void ABird::F_MoveForward(float value)
{
	if ((Controller != nullptr) && (value != 0.f))
	{
		FVector ActorForwardVector = GetActorForwardVector();
		AddMovementInput(ActorForwardVector, value);
	}
}

/*函数:左右移动*/
void ABird::F_MoveRight(float value)
{
	if ((Controller != nullptr) && (value != 0.f))
	{
		FVector ActorRightVector = GetActorRightVector();
		AddMovementInput(ActorRightVector, value);
	}
}

/*函数:左右看*/
void ABird::F_Turn(float value)
{
	if ((Controller != nullptr) && (value != 0.f))
	{
		//改变控制器偏航
		AddControllerYawInput(value);
	}
}

/*函数:上下看*/
void ABird::F_LookUp(float value)
{
	if ((Controller != nullptr) && (value != 0.f))
	{
		AddControllerPitchInput(value);
	}
}


